package cn.ywsj.ywsjmidtier.controller;

import cn.ywsj.ywsjmidtier.entity.VO.GoodsReceiptAddressQueryVo;
import cn.ywsj.ywsjmidtier.entity.VO.GoodsReceiptAddressVo;
import cn.ywsj.ywsjmidtier.service.WechatGoodsReceiptAddressFeign;
import cn.ywsj.ywsjmidtier.utils.JsonObjectUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "收货地址")
@RestController
@RequestMapping("/wechat/member/addressmgr")
public class WechatGoodsReceiptAddressController {
    @Autowired
    private WechatGoodsReceiptAddressFeign wechatGoodsFeign;

    /**
     * 地址管理列表
     * @param goodsVo
     * @param start
     * @param pageSize
     * @return
     */
    @ApiOperation("地址管理列表")
    @PostMapping("/ajaxgoodsaddresslist")
    public String ajaxgoodsaddresslist(GoodsReceiptAddressQueryVo goodsVo, Integer start, Integer pageSize) {
        JSONObject jsonObject = JsonObjectUtil.ObjectToJson(goodsVo);
        return wechatGoodsFeign.ajaxgoodsaddresslist(jsonObject,start, pageSize);
    }

    /**
     * 新增地址
     * @param addressVo
     * @param result
     * @return
     */
    @ApiOperation("新增地址")
    @PostMapping("/ajaxaddaddress")
    public String ajaxaddaddress(GoodsReceiptAddressVo addressVo, BindingResult result){
        /*MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("consignee",addressVo.getConsignee());
        map.add("phone",addressVo.getPhone());
        map.add("areAllName",addressVo.getAreAllName());
        map.add("isDefault",addressVo.getIsDefault());
        map.add("streetAddress",addressVo.getStreetAddress());
        map.add("areaId",addressVo.getAreaId());*/
        JSONObject jsonObject = JsonObjectUtil.ObjectToJson(addressVo);
        return wechatGoodsFeign.ajaxaddaddress(jsonObject,result);
    }

    /**
     * 修改地址
     * @param addressVo
     * @param result
     * @return
     */
    @ApiOperation("修改地址")
    @PostMapping("/ajaxupdateaddress")
    public String ajaxupdateaddress(GoodsReceiptAddressVo addressVo,BindingResult result){
        /*MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("consignee",addressVo.getConsignee());
        map.add("phone",addressVo.getPhone());
        map.add("areAllName",addressVo.getAreAllName());
        map.add("isDefault",addressVo.getIsDefault());
        map.add("streetAddress",addressVo.getStreetAddress());
        map.add("areaId",addressVo.getAreaId());
        map.add("addressId",addressVo.getAddressId());*/
        JSONObject jsonObject = JsonObjectUtil.ObjectToJson(addressVo);
        return wechatGoodsFeign.ajaxupdateaddress(jsonObject,result);
    }

    /**
     * 删除地址
     * @param goodsVo
     * @param request
     * @return
     */
    @ApiOperation("删除地址")
    @PostMapping("/ajaxdeleteaddress")
    public String ajaxdeleteaddress(GoodsReceiptAddressVo goodsVo, HttpServletRequest request){
        /*MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("addressId",goodsVo.getAddressId());*/
        JSONObject jsonObject = JsonObjectUtil.ObjectToJson(goodsVo);
        return wechatGoodsFeign.ajaxdeleteaddress(jsonObject,request);
    }
}
